$(function() {

	//活动页面（首页切换）

	$('.hd-hot-list li').hover(function() {

		$(this).find('.shadow').show();

	}, function() {

		$(this).find('.shadow').hide();

	});

	//徒步人物评选（导航）

	$(window).scroll(function () {

		if ($(window).scrollTop() > 515) {

			$("#px-nav").addClass("set-fixed");

			$("#model6").css("display","block");

		}else{

			$("#px-nav").removeClass("set-fixed");

			$("#model6").css("display","none");

		}

	});

	//置顶

	$("#back-to-top").click(function(){

		$('body,html').animate({scrollTop:0},400);

		return false;

	});

	//活动页导航悬浮
	/*var h = $('.mdd-bd-nav').offset().top;
	
	$(window).scroll(function(){
		if($(window).scrollTop() >h ){$('.mdd-bd-nav').addClass('setfixed');}
		else{$('.mdd-bd-nav').removeClass('setfixed');}
	});
	
	var d_hd_1=$("#d-hd-1").offset().top-150; 
	var d_hd_2=$("#d-hd-2").offset().top-150; 
	var d_hd_3=$("#d-hd-3").offset().top-150; 
	var d_hd_4=$("#d-hd-4").offset().top-150; 
	var d_hd_5=$("#d-hd-5").offset().top-150; 
	var d_hd_6=$("#d-hd-6").offset().top-150; 
	var d_hd_7=$("#d-hd-7").offset().top-150; 
	var d_hd_9=$("#d-hd-9").offset().top-150; 
	var d_hd_10=$("#d-hd-10").offset().top-150; 

	$(window).scroll(function(event) {
		 var juanqu=$(document).scrollTop(); 
		 console.log(juanqu);
		 if(juanqu>= d_hd_10)
		 {
		 	$(".mdd-bd-nav li").eq(8).addClass('on').siblings().removeClass('on');
		 }
		 else if(juanqu>=d_hd_9)
		 {
		 	$(".mdd-bd-nav li").eq(7).addClass('on').siblings().removeClass('on');
		 }
		 else if(juanqu>=d_hd_7)
		 {
		 	$(".mdd-bd-nav li").eq(6).addClass('on').siblings().removeClass('on');
		 }
		 else if(juanqu>=d_hd_6)
		 {
		 	$(".mdd-bd-nav li").eq(5).addClass('on').siblings().removeClass('on');   
		 }
		 else if(juanqu>=d_hd_5)
		 {
		 	$(".mdd-bd-nav li").eq(4).addClass('on').siblings().removeClass('on');  
		 }
		 else if(juanqu>=d_hd_4)
		 {	
		 	$(".mdd-bd-nav li").eq(3).addClass('on').siblings().removeClass('on');    
		 }
		 else if(juanqu>=d_hd_3)
		 {
		 	$(".mdd-bd-nav li").eq(2).addClass('on').siblings().removeClass('on');  
		 }
		 else if(juanqu>=d_hd_2)
		 {	
		 	$(".mdd-bd-nav li").eq(1).addClass('on').siblings().removeClass('on');  
		 }
		 else if(juanqu>=d_hd_1)
		 {
		 	$(".mdd-bd-nav li").eq(0).addClass('on').siblings().removeClass('on');  
		 }
	});
*/

	//投票切换

	function voteItem(){

		var $items = $('.h-pp-bd > ul > li');

		var _len = $items.length;

		var _h = $items.height();

		var _mb = parseInt($items.css('marginBottom')) ;

		var ztHeight=_h+_mb;

		var countLine = Math.ceil(_len / 6);

		$('.h-pp-bd > ul').height((ztHeight) * countLine);

		var outline = 0;

		var setCount=countLine-3;

		var zHeight=$('.h-pp-bd').height();

		$('.pp-list .ctr-down').on('click', function(){

			$(this).siblings('.ctr-up').removeClass('disabled');

			var $box = $('.h-pp-bd > ul');

			outline ++;

			var _height = $box.height();

			if(outline<setCount){

				$box.animate({'margin-top': -1*ztHeight*outline}, 500);

			}

			else if(outline=setCount){

				$box.animate({'margin-top': -1*ztHeight*setCount}, 500);

				$(this).addClass('disabled');

			}

			else{

				$box.css({'margin-top': -1*ztHeight*(setCount)});

				outline=setCount;

			}

		});

		$('.pp-list .ctr-up').on('click', function(){

			$(this).siblings('.ctr-down').removeClass('disabled');

			var $box = $('.h-pp-bd > ul');

			if(outline >1){

				outline--;

				$box.animate({'margin-top': -1*ztHeight*outline}, 500);

			}

			else if(outline=1){

				$box.animate({'margin-top': 0}, 500);

				$(this).addClass('disabled');

				outline=0;

			}

		});

	}

	voteItem();



  //官方活动搜索框

	//城市选择

  $('.sfliter .arrow').click(function(){
	var $parent = $(this).parents('.sfliter');

	var $sibselect = $parent.siblings('.sfliter').find('.fresult');

	if ($sibselect.css('display') == 'block') {

	  $sibselect.css('display', 'none');

	}

	$parent.find('.fresult').slideToggle();
  });

  //字母选择

	$(".ac_tab li").click(function(event) {

		var _tabIndex=$(this).index();

		$(this).addClass('on').siblings().removeClass('on');

		$(this).parent().parent().siblings('.ac_box').children('.tab-panel').eq(_tabIndex).addClass('on').siblings().removeClass('on')

	});



	//赋值

	$('#province_item li>a').click(function(){

		var _value = $(this).text();

		dom.find('span').text(_value);

		$('#provinceBox').hide();



	});



	$('.fresult a').click(function() {

		var city_name=$(this).text();

		$('.sfliter .f .p').text(city_name);

		$('.fresult').hide();

	});



	//展开筛选条件

	$('.moreFliter .more').click(function(event) {

		var $this = $(this);

		var $p = $this.parents('.moreFliter');

		var $box=$('.moreFliterBox');



		/*$p.parents('.fgroup').find('.moreFliterBox').toggleClass('fn-none');*/



		if($box.hasClass("fn-none")){

			$this.addClass('on');

			$this.find('a').text('收起筛选条件');

			$box.removeClass("fn-none");

		}else{

			$this.removeClass('on');

			$this.find('a').text('更多筛选条件');

			$box.addClass("fn-none");

		}

	});



	//报名列表

	$(".sign-nav a").click(function(event) {

		var signIndex=$(this).index();

		$(this).addClass('current').siblings().removeClass('current');

		$('.sign-list').eq(signIndex).addClass('current').siblings().removeClass('current');

	});



	//星级评分

	function SetScrore(dom){

		var _scrore = $(dom).attr('data-scrore');

		var _img = $(dom).children('img');

		if(_scrore == null || _scrore == ''){

			_img.attr({src:'images/star-off.png'});

		}else{

			var _index = parseInt(_scrore) / 2;

			for(var i = 0; i < _index; i ++){

				$(_img[i]).attr({src:'images/star-on.png'});

			}

		}

	}

	var oldScore=$('.score-raty-c .score-raty-l .score').text();

	$('.score-raty-c .score-raty-l img').on('mouseover',function(){

		var _index = $(this).index();

		var $parent = $(this).parent(),

			$friend = $parent.children('img'),

			$scrore_desc = $parent.next();

		$scrore_desc.children('span').text(Number((_index + 1) * 2).toFixed(1));

		$friend.attr({src:'images/star-off.png'});

		for(var i = 0; i <= _index; i++){

			$($friend[i]).attr({src:'images/star-on.png'});

		}

	});

	$('.score-raty-c .score-raty-l img').on('mouseout',function(){

		var _index = $(this).index();

		var $parent = $(this).parent(),

			$friend = $parent.children('img'),

			$scrore_desc = $parent.next();

		$friend.attr({src:'images/star-off.png'});

		var _scrore = $parent.attr('data-scrore');

		if(_scrore == null || _scrore == ''){

			$scrore_desc.children('span').text(oldScore);

		}else{

			$scrore_desc.children('span').text(_scrore);

		}

		SetScrore($parent);

	});

	$('.score-raty-c .score-raty-l img').on('click',function(){

		var _index = $(this).index();

		var $parent = $(this).parent();

		var $scrore_desc = $parent.next();

		$parent.attr({'data-scrore':Number((_index + 1) * 2).toFixed(1)});

		$(this).parents('.score-raty-wrap').find('#ratyValue').val(Number((_index + 1) * 2).toFixed(1));

		/*$parent.attr({'data-scrore':Number((_index + 1) * 2).toFixed(1)});*/

		$scrore_desc.children('span').text(Number((_index + 1) * 2).toFixed(1));

	});

	/*线路印象*/

	$(function(){

		var colors = ['l-color1', 'l-color2', 'l-color3', 'l-color4', 'l-color5', 'l-color6'];

		var _hasSpanStr = $('#spanValue').val();

		var spanList = [];

		if(_hasSpanStr != ''){

			spanList = _hasSpanStr.split(',');

		}

		function addSpan(){

			var _len = spanList.length;

			var _cl = colors.length;

			var _html = [];

			for(var i = 0; i < _len; i++){

				_html.push('<span class="' + colors[i % _cl] + '"> ' + spanList[i] +'</span>');

			}

			$('.impress-label').html(_html.join(''));

		}

		function checkHas(sp){

			var _len = spanList.length;



			for(var i = 0; i < _len; i++){

				if(sp == spanList[i]){

					return true;

				}

			}

			return false;

		}

		$('.impress-post').on('click', function (){

			var _sp = $('.impress-text').val();

			if(!checkHas(_sp)){



				// TODO:将数据保存后执行下面内容



				if(spanList.length > 0){

					var _v = $('#spanValue').val() + ',' + _sp;

					$('#spanValue').val(_v);

				}else{

					$('#spanValue').val(_sp);

				}

				console.log(_sp);

				spanList.push(_sp);

				addSpan();

				$('.impress-text').val('');

			}else{

				alert('添加的标签已经存在')

			}

		});

	});



});

